﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HotellApplikationASP
{
    public partial class AdminPage : System.Web.UI.Page
    {
        private HotellbokningASPEntities db;
        protected void Page_Load(object sender, EventArgs e)
        {
            db = new HotellbokningASPEntities();
        }

        //protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    int index = GridView1.SelectedIndex;
        //    GridView1.Rows[index].BackColor = Color.Bisque;
        //    foreach (GridViewRow row in GridView1.Rows)
        //    {
        //        if(row.RowIndex != index)
        //            row.BackColor = Color.White;
        //    }

            
        //}

        protected void ButtonPaging_Click(object sender, EventArgs e)
        {
            GridView1.AllowPaging = !GridView1.AllowPaging;
        }

        public void GridView1_UpdateItem()
        {
            // AdressbokIgen.Customer item = null;
            // Load the item here, e.g. item = MyDataLayer.Find(id);

            int index = GridView1.EditIndex;
            int ID = int.Parse(GridView1.Rows[index].Cells[1].Text);

            var chk = (CheckBox)GridView1.Rows[index].Cells[3].Controls[0];

            var item = db.Orders.Find(ID);
            if (item == null)
            {
                // The item wasn't found
                ModelState.AddModelError("",
                String.Format("Item with id {0} was not found", ID));
                return;
            }
            TryUpdateModel(item);
            if (ModelState.IsValid)
            {
                item.IsPayed = chk.Checked;
                //item.IsPayed = 
                // Save changes here, e.g. MyDataLayer.SaveChanges();
                db.SaveChanges();
            }
        }

        public IQueryable<Order> GridView1_GetData()
        {
            return db.Orders;
        }
    }
}